<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>项目列表</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/css/oksub.css">
    <script type="text/javascript" src="/static/lib/loading/okLoading.js"></script>
</head>
<body>
<div class="ok-body">
    <blockquote class="layui-elem-quote" style="margin: 5px 0px;">项目管理>项目管理</blockquote>
    <!--模糊搜索区域-->
    <div class="layui-row">
        <form class="layui-form ok-search-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" style="width: 340px;" name="searchname" id="searchname" class="layui-input" placeholder="姓名/职员代码/邮箱/手机号" autocomplete="off"
                               name="serachname">
                    </div>
                </div>
                <button class="layui-btn" style="margin-left: 150px;margin-bottom: 10px;" lay-submit="" lay-filter="search">
                            <i class="layui-icon">&#xe615;</i>
                        </button>
            </div>
        </form>
    </div>
    <!--数据表格-->
    <table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
<!--js逻辑-->
<script src="/static/lib/layui/layui.js"></script>
<script>
    layui.use(["element", "jquery", "table", "form", "laydate", "okLayer", "okUtils", "okMock"], function () {
        let table = layui.table;
        let form = layui.form;
        let laydate = layui.laydate;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;
        let okMock = layui.okMock;
        let $ = layui.jquery;
        okLoading.close($);

        let userTable = table.render({
            defaultToolbar: ['print', 'exports'],
            elem: '#tableId',
            id: 'tableId',
            url: '{% url "project:project_list" %}',
            limit: 20,
            height: 'full-140',
            page: true,
            toolbar: "#toolbarTpl",
            size: "sm",
            cols: [[
                {type: "checkbox", fixed: "left"},
                {field: "id", title: "ID", width: 60, sort: true},
                {field: "pro_name", title: "项目名称",event: 'ref_detail',style:"color:#1E9FFF;cursor:pointer", width: 220},
                {field: "paper_code", title: "关联协议",event: 'ref_contract', style:"color:#5FB878;cursor:pointer",width: 200},
                {field: "audit_customer", title: "被审计单位", width: 200},
                {field: "paper_manager", title: "项目负责人", width: 200},
                {field: "pro_number", title: "文号", width: 200},
                {field: "sign_one", title: "签字人1", width: 200},
                {field: "sign_two", title: "签字人2", width: 200},
                {field: "user_user", title: "user_user", hide:true},
                {field: "user_Independence", title: "user_Independence",hide:true},
                {field: "print_amount", title: "打印份数", width: 200},
                {field: "create_time", title: "创建时间", width: 200},
                {field: "remark", title: "备注", width: 200},
                {field: "now_status", title: "项目状态", width: 100,fixed:"right", templet: "#statusTpl"},
                {title: "操作", align: "center", width: 220, fixed: "right", templet: "#operationTpl"}
            ]],
            done: function (res, curr, count) {

            }
        });
         table.on('toolbar(tableFilter)', function (obj) {
            let checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据
            switch (obj.event) {
                case 'add':
                    add();
                    break;
            }
        });
        // 这个地方说了个寂寞
        table.on("tool(tableFilter)", function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "edit":
                    edit(data);
                    break;
                case "reset":
                    reset(data);
                    break;
                case "del":
                    del(data);
                    break;
            }
        });
        //
        table.on('tool(tableFilter)',function (obj) {
            let event = obj.event;
            if(event==='ref_detail'){
                okLayer.open("项目详细信息", "{% url 'project:project_detail_view' %}","90%", "90%", function (layero, index) {
                var iframe = window['layui-layer-iframe' + index];
                iframe.child(obj.data);
            })
            }else if(event==='ref_contract'){
                console.log(obj.data.paper_code)
            }
        });
        function add() {
            okLayer.open("创建项目", "{% url 'project:project_insert_view' %}", "90%", "90%", null, function () {
                userTable.reload();
            })
        }

        function edit(data) {
            okLayer.open("更新员工信息", "{% url 'users:users_edit_view' %}", "90%", "90%", function (layero, index) {
                var iframe = window['layui-layer-iframe' + index];
                iframe.child(data);
            })
        }

        function reset(data) {
            okLayer.confirm("确定要重置密码吗？", function () {
                okUtils.ajax("/users/users_resetpass/" + data.user_code, "post", true).done(function (response) {
                    okUtils.tableSuccessMsg(response.msg);
                }).fail(function (error) {
                    console.log(error)
                });
            })
        }
        function del(data) {
            let status=data.is_active;
            let msg='';
            if(status===true){
                msg='确定要禁用吗？'
            }else{
                msg='确定要启用吗？'
            }
            okLayer.confirm(msg, function () {
                okUtils.ajax("/users/users_del/" + data.id, "post", true).done(function (response) {
                    okUtils.tableSuccessMsg(response.msg);
                }).fail(function (error) {
                    console.log(error)
                });
            })
        }
        // 查询
        form.on("submit(search)", function (data) {
			userTable.reload({
                url: "{% url 'users:users_search' %}",
				request: {
                    pageName: 'page' //页码的参数名称，默认：page
                    ,limitName: 'limit' //每页数据量的参数名，默认：limit
                },
				page: {curr: 1},
                where:{
                    "searchname":$('#searchname').val()
                }
			});
			return false;
    })});
</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
    {% for l in data1 %}
        {% if l.menu_code == '300101' %}
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="add"><i class="layui-icon">&#xe608;</i>创建项目</button>
    {% endif %}
{% endfor %}
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
    {% for l in data1 %}
        {% if l.menu_code == '50500402' %}
    <a href="javascript:" title="更新员工信息" lay-event="edit"><button class="layui-btn layui-btn-xs">更新信息</button></a>
            {% elif l.menu_code == '50500403' %}
    <a href="javascript:" title="重置密码" lay-event="reset"><button class="layui-btn layui-btn-xs">重置密码</button></a>
    &nbsp;  {% elif l.menu_code == '50500404' %}
    <a href="javascript:" title="停用" lay-event="del"><button class="layui-btn layui-btn-danger layui-btn-xs">停/启用</button></a>
    {% endif %}
    {% endfor %}
</script>

<script type="text/html" id="statusTpl">
    {% verbatim %}
    {{#  if(d.now_status == 1){ }}
    <span class="layui-btn layui-btn-xs layui-btn-primary">拟定</span>
    {{#  } else if(d.now_status == 2) { }}
    <span class="layui-btn layui-btn-danger layui-btn-xs">终止</span>
    {{#  } }}
    {% endverbatim %}
</script>

</body>
</html>
